home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1257 / cobredoc.c_ / cobredoc.c
C/C++ Source or Header  |  1997-04-18  |  10KB  |  338 lines

  1. /* EasyCODE(C++) V5.1 02.03.1995 13:49:28 */
  2. /* EasyCODE O
  3. If=vertical
  4. LevelNumbers=no
  5. LineNumbers=no
  6. ScreenFont=Courier New,,80,9220,-11,0,400,0,0,0,0,0,0,3,2,1,49
  7. PrinterFont=Courier New,,80,17414,-34,0,400,0,0,0,0,0,0,3,2,1,49
  8. LastLevelId=383 */
  9.  
  10. /* EasyCODE ( 1
  11.    cobredoc.c */
  12.  
  13. /* EasyCODE ( 371
  14.    Includes, Constants */
  15. #include "convio.h"
  16. #include "conv.h"
  17. #include "tabledef.h"
  18. /* EasyCODE - */
  19. #define MAX_DELIMITERLEN  2
  20.  
  21. #define USAGEMSG    "Usage: %s inputfile outputfile\n"
  22.  
  23. #define ERR_TEXT1   "Keyword expected                           "
  24. #define ERR_TEXT2   "Unexpected EOF                             "
  25. #define ERR_TEXT3   "Keyword is not a valid COBOL keyword       "
  26. /* EasyCODE ) */
  27.  
  28. /* EasyCODE ( 372
  29.    StoreText */
  30.  
  31. /* EasyCODE F */
  32. void StoreText(FILE* stream, BOOL comment, char* contents)
  33.  
  34. // Writes text line to output file
  35.    {
  36.    if (comment)
  37.       {
  38.       // Only comments are written
  39.       if ((*contents == '/')||(*contents == '*'))
  40.          {
  41.          StoreLine(inbuf,stream);
  42.          }
  43.       else
  44.          {
  45.          // Text line is no comment
  46.          }
  47.       }
  48.    else
  49.       {
  50.       // comment == FALSE
  51.       // Not only comment is written
  52.       /* EasyCODE - */
  53.       StoreLine(inbuf,stream);
  54.       }
  55.    }
  56. /* EasyCODE ) */
  57.  
  58. /* EasyCODE ( 374
  59.    main */
  60.  
  61. /* EasyCODE F */
  62. void main(int argc, char *argv[])
  63.  
  64. // Reads lines from the input file and writes them to the 
  65. // output file. Empty lines are skipped. From each line
  66. // the keyword is extracted using GetKeyword() and the ID
  67. // is returned. If line is a text line it is checked whether
  68. // it is a comment line. If comment is not temporarily set 
  69. // to FALSE only comments are written. Lines that are not
  70. // text lines are written unmodified.
  71.    {
  72.    int    ID;               /* ID of actual keyword */
  73.    int    lineNum  = 0;     /* Actual line number */
  74.    char*  contents;         /* Content of actual line without */
  75.                             /* keyword+delimiter */
  76.    char*  delimiter;        /* Delimiter of actual keyword */
  77.    FILE*  fdr;              /* Input file */
  78.    FILE*  fdw;              /* Output file */
  79.    BOOL   bEOF = FALSE;     /* EOF indicator */
  80.    BOOL   comment = TRUE;   /* indicate whether only comments */
  81.                             /* are written */
  82.    /* EasyCODE - */
  83.    /* Allocate memory for pointers */
  84.    contents    = malloc(I_BUFSIZE*sizeof(char));
  85.    delimiter   = malloc((MAX_DELIMITERLEN+1)*sizeof(char));
  86.    
  87.    /* Initialize pointers */
  88.    *contents   = '\0';
  89.    *delimiter  = '\0';
  90.    if ((argc != 3))
  91.       {
  92.       fprintf (stderr, USAGEMSG, argv[0]);
  93.       exit(0);
  94.       }
  95.    if (((*argv[1]=='/') || (*argv[1]=='-')) ||
  96.        ((*argv[2]=='/') || (*argv[2]=='-')))
  97.       {
  98.       fprintf (stderr, USAGEMSG, argv[0]);
  99.       exit(0);
  100.       }
  101.    if (strcmp(argv[1],argv[2])==0)
  102.       {
  103.       fprintf (stderr, USAGEMSG, argv[0]);
  104.       exit(0);
  105.       }
  106.    fdr = OpenInput(argv[1]);
  107.    fdw = OpenOutput(argv[2]);
  108.    /* EasyCODE - */
  109.    bEOF = ReadLine(inbuf,fdr);
  110.    lineNum++;
  111.    while (!bEOF)
  112.       {
  113.       ID = GetKeyword(delimiter, contents);
  114.       switch (ID)
  115.          {
  116.          case ETF_EASYCODE:
  117.          case ETF_SHORTINFO:
  118.          case ETF_ENDSHORTINFO:
  119.          case ETF_OPTIONS:
  120.          case ETF_IFLAYOUT:
  121.          case ETF_LEVELNUMBERS:
  122.          case ETF_LINENUMBERS:
  123.          case ETF_CONSTRUCTNUMBERS:
  124.          case ETF_SCREENFONT:
  125.          case ETF_PRINTERFONT:
  126.          case ETF_LASTLEVELID:
  127.          case ETF_ENDOPTIONS:
  128.          case ETF_IF:
  129.          case ETF_THEN:
  130.          case ETF_ELSE:
  131.          case ETF_ENDIF:
  132.          case ETF_DUMMY:
  133.          case ETF_PERFORMTESTBEFORE:
  134.          case ETF_PERFORMTESTBEFOREBODY:
  135.          case ETF_ENDPERFORMTESTBEFORE:
  136.          case ETF_ONCONDITIONBRANCH:
  137.          case ETF_ONCONDITIONBRANCHBODY:
  138.          case ETF_ENDONCONDITIONBRANCH:
  139.          case ETF_ONSELECTORBRANCH:
  140.          case ETF_ONSELECTORBRANCHBODY:
  141.          case ETF_ENDONSELECTORBRANCH:
  142.          case ETF_TEXT:
  143.          case ETF_ENDTEXT:
  144.             StoreLine(inbuf,fdw);
  145.             break;
  146.          case ETF_LEVEL:
  147.             // comment temporarily set to FALSE in 
  148.             // order to always write the level header
  149.             /* EasyCODE - */
  150.             comment = FALSE;
  151.             /* EasyCODE - */
  152.             StoreLine(inbuf,fdw);
  153.             break;
  154.          case ETF_LEVELBODY:
  155.             comment = TRUE;
  156.             /* EasyCODE - */
  157.             StoreLine(inbuf,fdw);
  158.             break;
  159.          case ETF_ENDLEVEL:
  160.             StoreLine(inbuf,fdw);
  161.             break;
  162.          case ETF_LINE:
  163.             StoreText(fdw, comment, contents);
  164.             break;
  165.          case ETF_OFFSET:
  166.          case ETF_PERFORMBEFOREVARYING:
  167.          case ETF_PERFORMBEFOREVARYINGBODY:
  168.          case ETF_ENDPERFORMBEFOREVARYING:
  169.          case ETF_PERFORMTESTAFTER:
  170.          case ETF_UNTIL:
  171.          case ETF_ENDPERFORMTESTAFTER:
  172.             StoreLine(inbuf,fdw);
  173.             break;
  174.          case ETF_PERFORMOUTLINE:
  175.             // comment temporarily set to FALSE in 
  176.             // order to always write name
  177.             /* EasyCODE - */
  178.             comment = FALSE;
  179.             /* EasyCODE - */
  180.             StoreLine(inbuf,fdw);
  181.             break;
  182.          case ETF_ENDPERFORMOUTLINE:
  183.             comment = TRUE;
  184.             /* EasyCODE - */
  185.             StoreLine(inbuf,fdw);
  186.             break;
  187.          case ETF_EXIT:
  188.          case ETF_GOBACK:
  189.          case ETF_COBPROGRAM:
  190.          case ETF_IDDIV:
  191.          case ETF_ENVIRONMENTDIV:
  192.          case ETF_DATADIV:
  193.             StoreLine(inbuf,fdw);
  194.             break;
  195.          case ETF_PROCDIVPARAM:
  196.             // comment temporarily set to FALSE in 
  197.             // order to always write parameters
  198.             /* EasyCODE - */
  199.             comment = FALSE;
  200.             /* EasyCODE - */
  201.             StoreLine(inbuf,fdw);
  202.             break;
  203.          case ETF_PROCDIVBODY:
  204.             comment = TRUE;
  205.             /* EasyCODE - */
  206.             StoreLine(inbuf,fdw);
  207.             break;
  208.          case ETF_ENDCOBPROGRAM:
  209.             StoreLine(inbuf,fdw);
  210.             break;
  211.          case ETF_SECTION:
  212.             // comment temporarily set to FALSE in 
  213.             // order to always write the section name
  214.             /* EasyCODE - */
  215.             comment = FALSE;
  216.             /* EasyCODE - */
  217.             StoreLine(inbuf,fdw);
  218.             break;
  219.          case ETF_SECTIONBODY:
  220.             comment = TRUE;
  221.             /* EasyCODE - */
  222.             StoreLine(inbuf,fdw);
  223.             break;
  224.          case ETF_ENDSECTION:
  225.             StoreLine(inbuf,fdw);
  226.             break;
  227.          case ETF_PARAGRAPH:
  228.             // comment temporarily set to FALSE in 
  229.             // order to always write the paragraph name
  230.             /* EasyCODE - */
  231.             comment = FALSE;
  232.             /* EasyCODE - */
  233.             StoreLine(inbuf,fdw);
  234.             break;
  235.          case ETF_PARAGRAPHBODY:
  236.             comment = TRUE;
  237.             /* EasyCODE - */
  238.             StoreLine(inbuf,fdw);
  239.             break;
  240.          case ETF_ENDPARAGRAPH:
  241.          case ETF_PERFORMINLINE:
  242.          case ETF_ENDPERFORMINLINE:
  243.          case ETF_PERFORMTIMES:
  244.          case ETF_PERFORMTIMESBODY:
  245.          case ETF_ENDPERFORMTIMES:
  246.          case ETF_PERFORMAFTERVARYING:
  247.          case ETF_VARYING:
  248.          case ETF_ENDPERFORMAFTERVARYING:
  249.          case ETF_EXITPERFORM:
  250.          case ETF_EXITTOTEST:
  251.          case ETF_EXITPROGRAM:
  252.             StoreLine(inbuf,fdw);
  253.             break;
  254.          case ETF_EXTERNALCALL:
  255.             // comment temporarily set to FALSE in 
  256.             // order to always write name and parameters
  257.             /* EasyCODE - */
  258.             comment = FALSE;
  259.             /* EasyCODE - */
  260.             StoreLine(inbuf,fdw);
  261.             break;
  262.          case ETF_EXTERNALCALLPARAM:
  263.             StoreLine(inbuf,fdw);
  264.             break;
  265.          case ETF_ENDEXTERNALCALL:
  266.             comment = TRUE;
  267.             /* EasyCODE - */
  268.             StoreLine(inbuf,fdw);
  269.             break;
  270.          case ETF_SEARCH:
  271.          case ETF_ATEND:
  272.          case ETF_SEARCHBODY:
  273.          case ETF_ENDSEARCH:
  274.             StoreLine(inbuf,fdw);
  275.             break;
  276.          case ETF_ENTRY:
  277.             // comment temporarily set to FALSE in 
  278.             // order to always write the name and parameters
  279.             /* EasyCODE - */
  280.             comment = FALSE;
  281.             /* EasyCODE - */
  282.             StoreLine(inbuf,fdw);
  283.             break;
  284.          case ETF_ENTRYUSING:
  285.             StoreLine(inbuf,fdw);
  286.             break;
  287.          case ETF_ENDENTRY:
  288.             comment = TRUE;
  289.             /* EasyCODE - */
  290.             StoreLine(inbuf,fdw);
  291.             break;
  292.          case ETF_EXCEPTION:
  293.             // comment temporarily set to FALSE in 
  294.             // order to always write the exception
  295.             /* EasyCODE - */
  296.             comment = FALSE;
  297.             /* EasyCODE - */
  298.             StoreLine(inbuf,fdw);
  299.             break;
  300.          case ETF_ONEXCEPTION:
  301.             comment = TRUE;
  302.             /* EasyCODE - */
  303.             StoreLine(inbuf,fdw);
  304.             break;
  305.          case ETF_EXCEPTIONBODY:
  306.          case ETF_NOTEXCEPTIONBODY:
  307.          case ETF_ENDEXCEPTION:
  308.          case ETF_EVALUATE:
  309.          case ETF_EVALUATEBODY:
  310.          case ETF_EVALUATEOTHER:
  311.          case ETF_ENDEVALUATE:
  312.             StoreLine(inbuf,fdw);
  313.             break;
  314.          case NO_KEYWORD:
  315.             // Skip empty line
  316.             break;
  317.          case ERROR_KEYWORD:
  318.             err_msg(lineNum,ERR_TEXT1);
  319.             /* EasyCODE - */
  320.             exit(1);
  321.          case EOF_KEYWORD:
  322.             err_msg(lineNum,ERR_TEXT2);
  323.             /* EasyCODE - */
  324.             exit(1);
  325.          default:
  326.             err_msg(lineNum,ERR_TEXT3);
  327.             /* EasyCODE - */
  328.             exit(1);
  329.          }
  330.       bEOF = ReadLine(inbuf,fdr);
  331.       lineNum++;
  332.       }
  333.    CloseFile(fdr);
  334.    CloseFile(fdw);
  335.    }
  336. /* EasyCODE ) */
  337. /* EasyCODE ) */
  338.